#include "stdafx.h"
#include "PositionPatcher.h"
#include <list>
#include <iostream>

using namespace std;

void PositionPatcher::Patch(list<Player> & players, int buttonSeatNumber)
{
	list<Player>::iterator playerIt;
	playerIt = players.begin();
	
	if (players.size() == 2)
	{
		if (playerIt->SeatNum() == buttonSeatNumber)
		{
			playerIt->IsButton(true);
			playerIt->IsSb(true);		// when heads up, button is sb
			playerIt++;
			playerIt->IsBb(true);
		}
		else
		{
			playerIt->IsBb(true);
			playerIt++;
			playerIt->IsButton(true);
			playerIt->IsSb(true);
		}
		return;
	}

	int state = 0;		// 0 - button not yet found
						// 1 - button found
						// 2 - sb found
	
	while(true)
	{
		if (playerIt == players.end())
			playerIt = players.begin();

		if (playerIt->SeatNum() == buttonSeatNumber)
		{
			playerIt->IsButton(true);
			state = 1;
		}
		else if (state == 1)
		{
			playerIt->IsSb(true);
			state = 2;
		}
		else if (state == 2)
		{
			playerIt->IsBb(true);			
			return;
		}
		
		playerIt++;		
	}
}